/**
 * @ClassName Offer05
 * @Description 剑指 Offer 05. 替换空格
 * @Author clockTown
 * @Date 2021/8/15 15:31
 * @Version 1.0
 */
class Offer05 {

}

/**
 * v0 遍历字符串，将空格替换为 %20 后重新拼接
 */
class Offer05V0{
    public String replaceSpace(String s) {
        char space = ' ';
        char[] chars = s.toCharArray();
        StringBuilder res = new StringBuilder();
        for (char c : chars) {
            if (c - space == 0){
                res.append("%20");
            }else {
                res.append(c);
            }
        }
        return res.toString();
    }
}

/**
 * v1 正则
 */
class Offer05V1{
    public String replaceSpace(String s) {
        return s.replaceAll(" ", "%20");
    }
}